<template>
    <div class="distributionStationing-view">
        <el-dialog :title="titleText" :visible.sync="dialogFormVisible" width="10%" :show-close="showimg">
            <div slot="footer" class="dialog-footer">
                <el-button class="cancel-button"  @click="closeForm" >取 消</el-button>
                <el-button class="sure-button" type="primary" @click="addstruct">保 存</el-button>
            </div>
            <div>
                <el-table
                        :data="list"
                        style="width: 100%"
                        @selection-change="changeFun">
                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>
                    <el-table-column
                            prop="id"
                            label="序号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="account"
                            label="帐号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="name"
                            width="130"
                            label="姓名">
                    </el-table-column>
                    <el-table-column
                            prop="phone"
                            width="130"
                            label="手机号">
                    </el-table-column>
                    <el-table-column
                            prop="degree"
                            width="180"
                            label="职位">
                    </el-table-column>
                </el-table>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "distributionStationing",
        data(){
            return{
                organizationId: this.$store.getters.userData.userMsg.id,//组织id
                titleText:"分配驻场",
                showimg:false,
                list:[],
                totalpag:0,
                distributionlist:"",
            }
        },
        props:{
            dialogFormVisible: {
                type: Boolean
            },
            linkerIds:{
                type: String
            },
        },
        mounted(){
            this.getlist()
        },
        methods: {
            changeFun (val) {
                // 返回的是选中的列的数组集合
                let multipleSelection= val.map(item=>item.id+"")
                this.distributionlist = multipleSelection.join(",")

                // console.log("???????????",val)
            },
            closeForm() {
                console.log("aaaaaaa")
                this.$emit("close");
            },
            addstruct(){
                let _this = this;
                let params={
                    linkerIds:this.linkerIds,
                    userId:this.distributionlist
                }
                if( this.distributionlist){
                    console.log("pppppppppppppppppppp",params)
                    _this.Api.setting.distSetAllHouseResident(params).then((data)=>{
                        if(data.returnCode==10000){
                            //刷新列表
                            this.$emit("refreshList")
                            this.$emit("close");
                            this.$message({
                                type: 'success',
                                message: '分配成功!'
                            });
                        }else {
                            this.$message({
                                type: 'warning',
                                message: data.msg
                            });
                        }

                    })
                }else {
                    this.$alert('您还没勾选操作内容', '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }

            },
            getlist(){
                let _this = this;
                let params={
                    distributorId:this.organizationId,
                }
                console.log("pppppppppppppppppppp",params)
                _this.Api.setting.queryResidentList(params).then((data)=>{
                    console.log("aaaaaaaaaaaaaaa",data)
                    _this.totalpag=data.data.total;
                    _this.list=data.data.records;
                })
            }
        }

    }
</script>

<style scoped>

</style>